package com.h3bpm.kumhosunny.h3bpm;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import javax.servlet.http.HttpServletResponse;

import OThinker.Common.Organization.Models.User;
import OThinker.H3.Controller.Controllers.ProcessModel.RunBizQueryController;
import OThinker.H3.Entity.BizBus.Filter.*;
import OThinker.H3.Entity.Configs.ResourceManager;
import OThinker.H3.Entity.Tracking.UserLogType;
import OThinker.H3.Entity.WorkflowTemplate.WorkflowDocument.PublishedWorkflowTemplate;
import com.h3bpm.base.user.UserValidator;
import com.h3bpm.base.util.InstanceOperationLogHelper;
import net.sf.json.JSONObject;

import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.lang.StringUtils;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.JavaType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import OThinker.Common.DateTimeUtil;
import OThinker.Common.DotNetToJavaStringHelper;
import OThinker.Common.RefObject;
import OThinker.Common.SplitUtil;
import OThinker.Common.TimeSpan;
import OThinker.Common.Data.BoolMatchValue;
import OThinker.Common.Data.ComparisonOperatorType;
import OThinker.Common.Organization.Models.Unit;
import OThinker.Common.Organization.enums.State;
import OThinker.Common.Organization.enums.UnitType;
import OThinker.H3.Controller.ControllerBase;
import OThinker.H3.Controller.ViewModels.ActionResult;
import OThinker.H3.Controller.ViewModels.FilterDataViewModel;
import com.h3bpm.base.model.GridViewModel;
import OThinker.H3.Controller.ViewModels.Item;
import com.h3bpm.base.model.PagerInfo;
import OThinker.H3.Controller.ViewModels.TestServiceViewModel;
import com.h3bpm.base.consts.SheetEnviroment;
import com.h3bpm.base.util.SheetUtility;
import com.h3bpm.base.enums.SheetMode;
import OThinker.H3.Entity.Acl.BizObjectAcl;
import OThinker.H3.Entity.Acl.FunctionNode;
import OThinker.H3.Entity.BizBus.BizService.BizServiceInvokingContext;
import OThinker.H3.Entity.BizBus.BizService.BizStructure;
import OThinker.H3.Entity.BizBus.BizService.BizStructureUtility;
import OThinker.H3.Entity.BizBus.BizService.ItemSchema;
import OThinker.H3.Entity.BizBus.BizService.MethodSchema;
import OThinker.H3.Entity.Data.DataLogicType;
import OThinker.H3.Entity.Data.Metadata.EnumerableMetadata;
import OThinker.H3.Entity.DataModel.ActionType;
import OThinker.H3.Entity.DataModel.BizObject;
import OThinker.H3.Entity.DataModel.BizObjectSchema;
import OThinker.H3.Entity.DataModel.BizQuery;
import OThinker.H3.Entity.DataModel.BizQueryAction;
import OThinker.H3.Entity.DataModel.BizQueryColumn;
import OThinker.H3.Entity.DataModel.BizQueryItem;
import OThinker.H3.Entity.DataModel.ControlType;
import OThinker.H3.Entity.DataModel.FilterType;
import OThinker.H3.Entity.DataModel.PropertySchema;
import OThinker.H3.Entity.Instance.InstanceContext;
import OThinker.H3.Entity.Instance.Data.InstanceData;
import OThinker.H3.Entity.WorkSheet.BizSheet;
import OThinker.H3.Entity.WorkSheet.SheetType;
import data.DataRow;
import data.DataTable;

/**
 * @authormi
 * @date2019/11/6
 */
@Controller
@RequestMapping(value="/Portal/RunBizQueryKumhosunny")
@Scope("prototype")
public class RunBizQueryKumhosunnyController extends ControllerBase{


        private static final long serialVersionUID = 7543727883349836888L;

        private static final Logger LOGGER = LoggerFactory.getLogger(OThinker.H3.Controller.Controllers.ProcessModel.RunBizQueryController.class);

        /**
         节点编码

         */
        @Override
        public String getFunctionCode()
        {
            return FunctionNode.ProcessModel_BizMasterData_Code;
        }

        /**
         获取或设置业务对象编码

         */
        private String privateSchemaCode;
        public String getSchemaCode()
        {
            return privateSchemaCode;
        }
        public void setSchemaCode(String value)
        {
            privateSchemaCode = value;
        }

        /**
         获取或设置查询编码

         */
        private String privateQueryCode;
        public String getQueryCode()
        {
            return privateQueryCode;
        }
        public void setQueryCode(String value)
        {
            privateQueryCode = value;
        }

        /**
         获取或设置显示主数据的宿主控件ID

         */
        public final String getCtrlID()
        {
            return this.request.getParameter("CtrlID");
        }


        /**
         * 获取或设置窗体的打开方式，默认是0：以window.open方式打开的，1：以iframe方式打开的
         *
         * @return
         * @throws UnsupportedEncodingException
         */
        protected final String getOpenType() throws UnsupportedEncodingException
        {
            if(this.request.getParameter("OpenType") == null)return "0";
            String openType = URLDecoder.decode(this.request.getParameter("OpenType"), "UTF-8");
            openType = DotNetToJavaStringHelper.isNullOrEmpty(openType) ? "0" : openType;
            return openType;
        }

        /**
         是否为开窗查询模式

         */
        protected final boolean getIsPopup()
        {
            return !DotNetToJavaStringHelper.isNullOrEmpty(this.request.getParameter("IsPopup"));
        }

        private String _ListMethod = "GetList";

        /**
         * 获取或设置查询编码
         *
         * @return
         * @throws Exception
         */
        public String getListMethod() throws Exception
        {
            if (this.getQuery() != null)
            {
                return this._ListMethod;
            }
            return this._ListMethod;
        }
        public void setListMethod(String value)
        {
            _ListMethod = value;
        }

        private BizQuery _Query;

        /**
         * 获取或设置业务对象的查询方法
         *
         * @return
         * @throws Exception
         */
        protected final BizQuery getQuery() throws Exception {
            if (_Query == null) {
                _Query = getEngine().getBizObjectManager().GetBizQuery(getQueryCode());
                if (_Query == null) {
                    throw new Exception(String.format("主数据[%1$s]不存在查询编码[%2$s]。", getSchemaCode(), getQueryCode()));
                }
            }
            return _Query;
        }

        private List<BizQueryItem> _lstVisibleQueryItems;
        private List<BizQueryItem> getlstVisibleQueryItems() throws Exception {
            if (_lstVisibleQueryItems == null || _lstVisibleQueryItems.size() == 0) {
                _lstVisibleQueryItems = new ArrayList<BizQueryItem>();
                if (getQuery() != null && getQuery().getQueryItems() != null) {
                    for (BizQueryItem item : getQuery().getQueryItems()){
                        if (item.getVisible() == BoolMatchValue.True) {
                            //update by zhangj
                            item.setPropertyCode(item.getPropertyName());
                            //新增PropertyCode
                            PropertySchema propertySchema = this.getSchema().GetProperty(item.getPropertyCode());
                            if (propertySchema != null) {
                                item.setPropertyName(propertySchema.getDisplayName());
                            }
                            _lstVisibleQueryItems.add(item);
                        }
                    }
                }
            }
            return _lstVisibleQueryItems;
        }

        private BizObjectSchema _Schema = null;

        /**
         * 获取当前对象的Schema
         *
         * @return
         * @throws Exception
         */
        protected final BizObjectSchema getSchema() throws Exception {
            if (_Schema == null) {
                this._Schema = getEngine().getBizObjectManager().GetPublishedSchema(this.getSchemaCode());
            }
            return _Schema;
        }

        /**
         是否显示功能按钮

         */
        protected boolean getActionVisible()
        {
            return true;
        }

        private String _OutputPropertyMappings;

        /**
         * 获取或设置业务对象/属性的输出参数
         *
         * @return
         * @throws UnsupportedEncodingException
         */
        public final String getOutputPropertyMappings() throws UnsupportedEncodingException
        {
            if (DotNetToJavaStringHelper.isNullOrEmpty(_OutputPropertyMappings))
            {
                if(this.request.getParameter("OutputParams") == null) return "";
                _OutputPropertyMappings = URLDecoder.decode(
                        this.request.getParameter("OutputParams"), "UTF-8");
            }
            return _OutputPropertyMappings;
        }
        public final void setOutputPropertyMappings(String value)
        {
            _OutputPropertyMappings = value;
        }

        private String _InputPropertyMappings;

        /**
         * 获取或设置业务对象/属性的输入参数
         *
         * @return
         * @throws UnsupportedEncodingException
         */
        private String getInputPropertyMappings() throws UnsupportedEncodingException
        {
            if (_InputPropertyMappings == null)
            {
                _InputPropertyMappings = this.request.getParameter("InputParam") == null
                        ? "" : URLDecoder.decode(this.request.getParameter("InputParam"), "UTF-8");
            }
            return _InputPropertyMappings;
        }

        /**
         表头

         */
        protected List<Map<String, String>> GirdColumns = new ArrayList<Map<String, String>>();

        /**
         * 获取页面所需数据
         *
         * @param schemaCode
         * 			数据模型编码
         * @param queryCode
         * 			查询编码
         * @return 页面数据
         * @throws UnsupportedEncodingException
         * @throws Exception
         */
        @ResponseBody
        @RequestMapping(value="/GetRunBizQueryData",method=RequestMethod.GET)
        public final ActionResult GetRunBizQueryData(String schemaCode, String queryCode)
                throws UnsupportedEncodingException, Exception {
            this.setSchemaCode(URLDecoder.decode(schemaCode,"utf-8"));
            this.setQueryCode(URLDecoder.decode(queryCode,"utf-8"));
            ActionResult result = new ActionResult();
            Map<String, Object> param = new HashMap<String, Object>(2);
            CreateColumns();
            param.put("isFrame", this.getOpenType().equals("1"));
            param.put("isReturn", SplitUtil.Splits(
                    this.getOutputPropertyMappings(), new String[] { " | " }, true).length > 0);
            param.put("outputPropertyMappings", this.getOutputPropertyMappings());
            param.put("CtrlID", this.getCtrlID());
            param.put("SchemaCode", this.getSchemaCode());
            param.put("ActionVisible", this.getActionVisible());
            param.put("Param_BizObjectID", SheetEnviroment.Param_BizObjectID);
            param.put("Param_SchemaCode", SheetEnviroment.Param_SchemaCode);
            param.put("GirdColumns", GirdColumns);
            param.put("BizQueryActions", GetActions());
            param.put("DisplayFormats", GetDisplayFormats());
            //Update by linjh
            param.put("FilterData", GetVisibleFilterData());
            //update by zhangj
            param.put("ListDefault", _Query.getListDefault().getValue());
            result.setSuccess(true);
            result.setExtend(param);
            return result;
        }


        /**
         * 获取列表数据
         *
         * @param schemaCode
         * 			数据模型编码
         * @param queryCode
         * 			查询编码
         * @param filterStr
         * 			过滤条件
         * @param pageInfo
         * 			分页信息
         * @return
         * @throws Exception
         * update by zhangj
         */
        @ResponseBody
        @RequestMapping(value="/GetGridData",method={RequestMethod.GET,RequestMethod.POST})
        public final Map<String, Object> GetGridData(String schemaCode, String queryCode,
                                                     String FilterStr, PagerInfo pageInfo) throws Exception
        {
            LOGGER.info("schemaCode:" + schemaCode + ",queryCode:" + queryCode + ",FilterStr:" + FilterStr);
            this.setSchemaCode(URLDecoder.decode(schemaCode,"utf-8"));
            this.setQueryCode(URLDecoder.decode(queryCode,"utf-8"));
            int totalCount = 0;
            RefObject<Integer> tempRef_totalCount = new RefObject<Integer>(totalCount);
            List<Object> dataList = GetGridDataList(FilterStr, pageInfo, tempRef_totalCount);
            this.request.getSession().setAttribute(this.request.getRequestURI(), null);
            Map<String, Object> extend = new HashMap<String, Object>(2);
            extend.put("Rows", dataList);

            extend.put("Total", tempRef_totalCount.argvalue);
            return extend;
        }




    /**
         * 获取查询出的数据列以及总大小
         *
         * @param filterStr
         * 			过滤参数
         * @param pageInfo
         * 			分页信息
         * @param totalCount
         * 			返回的总数
         * @return 表格数据
         * @throws Exception
         *
         * update by zhangj
         */
        private List<Object> GetGridDataList(String filterStr, PagerInfo pageInfo,
                                             RefObject<Integer> totalCount) throws Exception {
            Filter filter = (DotNetToJavaStringHelper.isNullOrEmpty(filterStr)||"{}".equals(filterStr))
                    ? new Filter() : GetFilter(filterStr);
            if(getQuery().getQueryItems() != null && DotNetToJavaStringHelper.isNullOrEmpty(filterStr)){
                filter = GetFilter("");
            }

            totalCount.argvalue = 0;
            int pageSize = pageInfo.getPageSize();
            int currentPageIndex = pageInfo.getPageIndex();

            //点击排序支持
            String SortName = this.request.getParameter("sortname");
            String SortOrder = this.request.getParameter("sortorder");
            SortDirection sortDirection = SortDirection.Ascending;
            if (!DotNetToJavaStringHelper.isNullOrEmpty(SortName))
            {
                if (!DotNetToJavaStringHelper.isNullOrEmpty(SortOrder)
                        && SortOrder.toLowerCase().equals("desc"))
                {
                    sortDirection = SortDirection.Descending;
                }
            }
            //如果没有指定排序,默认取第一列
            else
            {
                for (int i = 0; i < getQuery().getColumns().size(); i++)
                {
                    if (getQuery().getColumns().get(i).getVisible() == BoolMatchValue.True.getValue())
                    {
                        filter.AddSortBy(new SortBy(getQuery().getColumns().get(i).getPropertyName(),
                                SortDirection.Ascending));
                        break;
                    }
                }
            }
            filter.AddSortBy(new SortBy(SortName, sortDirection));

            if (filter.getSortByCollection() == null || filter.getSortByCollection().length == 0)
            {
                for (BizQueryColumn column : getQuery().getColumns())
                {
                    if (column.getVisible() == BoolMatchValue.True.getValue())
                    {
                        filter.AddSortBy(new SortBy(column.getPropertyName(), SortDirection.Ascending));
                        break;
                    }
                }
            }

            if (pageSize > 0)
            {
                filter.setFromRowNum((currentPageIndex - 1) * pageSize < 1
                        ? 1 : (currentPageIndex - 1) * pageSize + 1);
                filter.setToRowNum(filter.getFromRowNum() + pageSize - 1);
            }
            filter.setRequireCount(true);

            // 调用查询
            BizObject[] objs = this.getSchema().GetList(
                    this.getEngine().getOrganization(),
                    this.getEngine().getMetadataRepository(),
                    this.getEngine().getBizObjectManager(),
                    this.getUserValidator().getUserID(),
                    getListMethod(), filter, totalCount);

            List<Object> dataList = new ArrayList<Object>();
            if (objs != null) {
                //update by zhangj
			/*for (int i = 0; i < objs.length; i++) {
				BizObject biz = objs[i];
				for (int j = 0; j < getQuery().getColumns().size(); j++) {
					Object o = biz.getItem(getQuery().getColumns().get(j).getPropertyName());
					//审批意见
					//子表
					if(o != null && o instanceof BizObject[]){
						biz.setItem(getQuery().getColumns().get(j).getPropertyName(), "");
						continue;
					}
					if(o != null && o instanceof Object[]){
						Object[] obj = (Object[]) o;
						if(obj != null && obj[0] instanceof String){
							//参与者类型在后面代码处理 UPDATE BY ZHANGJ
							continue;
						}
						ItemSchema is = (ItemSchema) obj[0];
						if(DataLogicType.Comment == is.getLogicType()){
							biz.setItem(getQuery().getColumns().get(j).getPropertyName(), "");
						}
						if(DataLogicType.Attachment == is.getLogicType()){
							biz.setItem(getQuery().getColumns().get(j).getPropertyName(), "");
						}
					}
					if(o instanceof ItemSchema){
						ItemSchema is = (ItemSchema) o;
						if(is.getLogicType() == DataLogicType.Attachment){
							biz.setItem(getQuery().getColumns().get(j).getPropertyName(), "");
						}
					}
				}
			}*/

                //业务对象数组类型的属性名称
                List<String> VisiblePropertyNames = new ArrayList<String>();
                if (this.getSchema().getProperties() != null)
                {
                    for (PropertySchema p : this.getSchema().getProperties())
                    {
                        VisiblePropertyNames.add(p.getName());
                    }
                }

                List<String> UnitIDList = new ArrayList<String>();
                // 业务对象
                for (BizObject obj : objs){

                    if(obj.getValueTable() == null){
                        continue;
                    }



                    Map<String, Object> dicValueTable = new HashMap<String, Object>(4);
                    for (String pName : VisiblePropertyNames){

                        if(!obj.getValueTable().containsKey(pName)){
                            continue;
                        }

                        //单人参与者
                        if (this.getSchema().GetProperty(pName).getLogicType()
                                == DataLogicType.SingleParticipant
                                || pName.equals(BizObjectSchema.PropertyName_CreatedBy)
                                || pName.equals(BizObjectSchema.PropertyName_CreatedByParentId)){

                            UnitIDList.add(obj.getValueTable().get(pName) + "");
                        }else if (this.getSchema().GetProperty(pName).getLogicType() == DataLogicType.MultiParticipant) {
                            //多人参与者
                            HashMap<String, Object> map = obj.getValueTable();
                            if(map.get(pName) == null){
                                continue;
                            }

                            //修复获取多人参与者显示异常的问题
                            if(!(map.get(pName) instanceof String[]) || ArrayUtils.isEmpty(((String[])map.get(pName)))){
                                continue;
                            }

                            for (String participant : (String[])map.get(pName)){
                                UnitIDList.add(participant);
                            }

                        }
                    }

                    List<Unit> Units = this.getEngine().getOrganization().GetUnits(UnitIDList);
                    Map<String, Unit> UnitDictionary = new HashMap<String, Unit>();
                    if (Units != null && Units.size() > 0){
                        for (Unit u : Units){
                            if (UnitDictionary.containsKey(u.getObjectID())){
                                continue;
                            }

                            UnitDictionary.put(u.getObjectID(), u);
                        }
                    }

                    for (String pName : VisiblePropertyNames){

                        if(!obj.getValueTable().containsKey(pName)){
                            continue;
                        }

                        if(this.getSchema().GetProperty(pName).getLogicType() == DataLogicType.Comment){
                            continue;
                        }

                        if(this.getSchema().GetProperty(pName).getLogicType() == DataLogicType.Attachment){
                            continue;
                        }


                        //单人参与者
                        if (this.getSchema().GetProperty(pName).getLogicType() == DataLogicType.SingleParticipant){
                            if (UnitDictionary.containsKey(obj.getValueTable().get(pName) + "")){
                                dicValueTable.put(pName, GetUnitDisplayHtml(
                                        UnitDictionary.get(obj.getValueTable().get(pName) + "")));
                            }
                            else{
                                dicValueTable.put(pName, obj.getValueTable().get(pName)==null
                                        ?"":obj.getValueTable().get(pName)+ "");
                            }
                        }else if (this.getSchema().GetProperty(pName).getLogicType() == DataLogicType.MultiParticipant){
                            //多人参与者
                            HashMap<String, Object> map = obj.getValueTable();
                            if(map.get(pName) == null){
                                continue;
                            }

                            //修复获取多人参与者显示异常的问题
                            if(!(map.get(pName) instanceof String[]) || ArrayUtils.isEmpty(((String[])map.get(pName)))){
                                dicValueTable.put(pName, obj.getValueTable().get(pName));
                                continue;
                            }

                            String multiParticipantString = "";
                            for (String participant : (String[])map.get(pName)){
                                if (UnitDictionary.containsKey(participant)){
                                    multiParticipantString += GetUnitDisplayHtml(
                                            UnitDictionary.get(participant)) + ";";
                                }
                                else{
                                    multiParticipantString += participant + ";";
                                }
                            }

                            dicValueTable.put(pName, multiParticipantString);

                        }else if(this.getSchema().GetProperty(pName).getLogicType() == DataLogicType.DateTime){
                            //update by zhangj
                            Object value = obj.getValueTable().get(pName);

                            if(null == value){
                                dicValueTable.put(pName, "");
                                continue;
                            }

                            if(value instanceof String && StringUtils.isBlank(value.toString())){
                                dicValueTable.put(pName, "");
                                continue;
                            }

                            SimpleDateFormat fmt = new  SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                            Date dateValue = null;
                            if(value instanceof Date){
                                dateValue = (Date) value;
                            }else {
                                dateValue = fmt.parse(value.toString());
                            }

                            Calendar cal = Calendar.getInstance();
                            cal.setTime(dateValue);
                            if(cal.get(Calendar.YEAR) < 1971 || cal.get(Calendar.YEAR) > 9000){
                                dicValueTable.put(pName, "-");
                            }else{
                                dicValueTable.put(pName,fmt.format(dateValue));
                            }

                        }else{
                            dicValueTable.put(pName, obj.getValueTable().get(pName));
                        }
                    }
                    dataList.add(dicValueTable);
                }
            }

            if(totalCount.argvalue == 0 || totalCount.argvalue == -1){
                totalCount.argvalue = dataList.size();
            }
            return dataList;
        }

        /**
         * 执行方法
         *
         * @param bizSchemaCode
         * 			业务模型编码
         * @param bizObjectID
         * 			所选行ID
         * @param methodName
         * 			执行方法名称
         * @return
         * @throws Exception
         * UPDATE BY ZHANGJ
         */
        @ResponseBody
        @RequestMapping(value="/InvokeMethod",method=RequestMethod.POST)
        public final ActionResult InvokeMethod(String bizSchemaCode, String bizObjectID, String methodName, String rowData) throws Exception {
            ActionResult result = new ActionResult();
            String BizSchemaCode = bizSchemaCode.trim();
            String BizObjectID = bizObjectID.trim();
            String MethodName = methodName.trim();

            if (StringUtils.isBlank(MethodName) || "null".equalsIgnoreCase(MethodName)) {
                String msg = ResourceManager.getString("RunBizQuery_BizMethodEmpty");
                String[] errors = new String[] { msg };
                result.setSuccess(false);
                result.setErrors(errors);
                return result;
            }

            UserValidator userValidator = this.getUserValidator();
            BizObject bizObject = new BizObject(
                    this.getEngine().getOrganization(),
                    this.getEngine().getMetadataRepository(),
                    this.getEngine().getBizObjectManager(),
                    this.getEngine().getBizBus(),
                    this.getEngine().getBizObjectManager().GetPublishedSchema(BizSchemaCode),
                    userValidator.getUserID(),
                    userValidator.getUser().getParentID());

            bizObject.setObjectID(BizObjectID);
            bizObject.Load(null);

            if (StringUtils.isEmpty(methodName) || "null".equalsIgnoreCase(methodName)) {
                result.setResult(false);
                result.setErrors(new String[]{"未绑定业务服务方法！"});
                return result;
            }

            //add by luwei : 传入行数据
            if (StringUtils.isNotBlank(rowData)) {
                com.alibaba.fastjson.JSONObject parseObject = com.alibaba.fastjson.JSONObject.parseObject(rowData);
                for (String key : parseObject.keySet()) {
                    parseObject.getString(key);
                    bizObject.SetValue(key, parseObject.getString(key));
                }
            }

            if (MethodName.equals(BizObjectSchema.MethodName_Remove))
            {
                //update by ouyangsk
                //if (!this.getUserValidator().ValidateBizObjectAdmin(BizSchemaCode, "",
                //		this.getUserValidator().getUserID()))
                if (!this.getUserValidator().ValidateBizObjectAdmin(BizSchemaCode, "",
                        bizObject.getOwnerId() == null ? "" : bizObject.getOwnerId()))
                {
                    String[] Errors = new String[] { "无管理权限" };
                    result.setResult(false);
                    result.setErrors(Errors);
                    return result;
                }
                else
                {
                    bizObject.invoke(MethodName);
                    result.setResult(true);
                    result.setNeedRefresh(true);
                    addLog(bizObject.getSchema(), userValidator.getUserID());
                    return result;
                }
            }
            else
            {
                bizObject.invoke(MethodName);
                result.setResult(true);
                return result;
            }
        }

        /**
         * add by luwei
         */
        private void addLog(BizObjectSchema schema, String userId) {
            String logName = "";
            String schemaCode = schema.getSchemaCode();
            try {
                PublishedWorkflowTemplate workflow = getEngine().getWorkflowManager().GetDefaultWorkflow(schemaCode);
                if (workflow == null) {
                    FunctionNode functionNode = getEngine().getFunctionAclManager().GetFunctionNodeByCode(schemaCode);
                    if (functionNode != null) {
                        logName = functionNode.getDisplayName();
                    }
                } else {
                    String displayName = getEngine().getWorkflowManager().GetClauseDisplayName(schemaCode);
                    logName = displayName + "." + workflow.getWorkflowVersion();
                }
            } catch (Exception e) {
                LOGGER.error("get workflow info error,{}", e);
            }
            InstanceOperationLogHelper.addLog(userId, schemaCode, logName, UserLogType.BizQueryDataDelete, false);
        }

        /**
         * 编辑或添加流程数据
         *
         * @param BizObjectID
         * 			对象ID
         * @param SchemaCode
         * 			数据模型编码
         * @param SheetCode
         * 			表单编码
         * @param Mode
         * 			打开表单的模式
         * @param AfterSave
         * 			保存后的动作
         * @param IsEditInstanceData
         * 			是否修改数据项模式
         * @param isMobile
         * 			是否是手机访问
         * @throws IOException
         * @throws Exception
         */
        @ResponseBody
        @RequestMapping(value="/EditBizObject",method=RequestMethod.GET)
        public final void EditBizObject(String BizObjectID, String SchemaCode, String SheetCode,
                                        String Mode, String AfterSave, String IsEditInstanceData, String isMobile,String go,
                                        HttpServletResponse servletResponse) throws IOException, Exception {
            //add by linjh@Future 2018.9.27 sql 注入
            BizObjectID = StringEscapeUtils.escapeSql(BizObjectID);
            SchemaCode = StringEscapeUtils.escapeSql(SchemaCode);
            SheetCode = StringEscapeUtils.escapeSql(SheetCode);
            Mode = StringEscapeUtils.escapeSql(Mode);
            AfterSave = StringEscapeUtils.escapeSql(AfterSave);
            IsEditInstanceData = StringEscapeUtils.escapeSql(IsEditInstanceData);
            isMobile = StringEscapeUtils.escapeSql(isMobile);
            go = StringEscapeUtils.escapeSql(go);

            // 兼容旧版本
            JSONObject json = null;
            if(json == null){
                String url = "";

                boolean mobile = false;
                String IsMobile = "false";       //前端可能传入大写IsMobile zcw

                if ("true".equals(request.getParameter("IsMobile")) || "true".equals(request.getParameter("isMobile"))) {
                    IsMobile = "true";
                }

                mobile = Boolean.valueOf(IsMobile);

                SheetMode sheetmode = SheetMode.valueOf(Mode);
                if (!DotNetToJavaStringHelper.isNullOrEmpty(IsEditInstanceData)) {
                    url = GetWorkSheetUrl(SchemaCode, BizObjectID, sheetmode, mobile);
                    url += "&EditInstanceData=true";
                } else {
                    BizSheet sheet = this.getEngine().getBizSheetManager().GetBizSheetByCode(SheetCode);
                    if (sheet == null) {
                        List<BizSheet> sheets = this.getEngine().getBizSheetManager().GetBizSheetBySchemaCode(SchemaCode);
                        if (sheets == null || sheets.size() == 0) {
                            throw new RuntimeException("流程包{" + SchemaCode + "}表单不存在，请检查。");
                        }
                        sheet = sheets.get(0);
                    }
                    //Update by linjh
                    if(sheet.getSheetType() == SheetType.DefaultSheet) {
                        url = GetWorkSheetUrl(SchemaCode, BizObjectID, sheetmode, mobile);
                    }else if (sheet.getSheetType() == SheetType.CustomSheet) {
                        //增加跳转自定义表单的路径
                        url = "/Portal/" + GetWorkSheetUrl(SchemaCode, BizObjectID, sheet, sheetmode, mobile) + "EditInstanceData=true";
                    }
                }
                //update by ouyangsk 用户均有权限编辑流程表单，所以加个参数，这样MvcPage中Onload时，通过参数判断如果为应用中心流程表单，则不加以表单权限检验
                String onlyDataStr = request.getParameter("onlyData");
                if (!DotNetToJavaStringHelper.isNullOrEmpty(onlyDataStr)) {
                    url += "&onlyData=true";
                }

                // add by zcw 区分移动端流程表单
                if(!DotNetToJavaStringHelper.isNullOrEmpty(go)){
                    url += "&go="+go;
                }

                servletResponse.sendRedirect(url);
            }
        }

        /**
         * 应用中心-流程列表（前端）
         *
         * @param BizObjectID
         * @param SchemaCode
         * @param SheetCode
         * @param Mode
         * @param IsMobile
         * @param EditInstanceData
         * @return
         * @throws Exception
         */
        @ResponseBody
        @RequestMapping(value="/EditBizObjectSheet",method=RequestMethod.POST)
        public final ActionResult EditBizObjectSheet(String BizObjectID,
                                                     String SchemaCode, String SheetCode, String Mode, boolean IsMobile,
                                                     String EditInstanceData) throws Exception
        {
            ActionResult result = new ActionResult(false, "");
            String url = "";
            SheetMode sheetMode = SheetMode.Work;
            sheetMode = SheetMode.valueOf(Mode);
            if (!DotNetToJavaStringHelper.isNullOrEmpty(EditInstanceData))
            {
                url = GetWorkSheetUrl(SchemaCode, BizObjectID, sheetMode, IsMobile);
                url += "&EditInstanceData=true";
            }
            else
            {
                BizSheet sheet = this.getEngine().getBizSheetManager().GetBizSheetByCode(SheetCode);
                if (sheet == null)
                {
                    List<BizSheet> sheets = this.getEngine().getBizSheetManager()
                            .GetBizSheetBySchemaCode(SchemaCode);
                    if (sheets == null || sheets.size() == 0)
                    {
                        throw new RuntimeException("流程包{" + SchemaCode + "}表单不存在，请检查。");
                    }
                    sheet = sheets.get(0);
                }
                url = GetWorkSheetUrl(SchemaCode, BizObjectID, sheet, sheetMode, IsMobile);
            }
            result.setMessage(url);
            result.setSuccess(true);

            return result;
        }

        /**
         * @Title: EditBizObjectSheet2
         * @Description:
         * @Param: @param BizObjectID
         * @Param: @param SchemaCode
         * @Param: @param SheetCode
         * @Param: @param Mode
         * @Param: @param IsMobile
         * @Param: @param EditInstanceData
         * @Param: @return
         * @Param: @throws Exception
         * @Return: Object
         * @throws
         * Add by linjh:增加原因 与EditBizObjectSheet有区别，Get方式。
         */
        @ResponseBody
        @RequestMapping(value="/EditBizObjectSheet",method=RequestMethod.GET)
        public final Object EditBizObjectSheet2(String BizObjectID, String SchemaCode,
                                                String SheetCode, String Mode, boolean IsMobile, String EditInstanceData)
                throws Exception{
            //update by ouyangsk 此处若检验functionCode，会造成普通用户无法访问应用中心流程表单的问题
            // 兼容旧版本
//		JSONObject json = ExecuteFunctionRun(null);
//		if(json != null){
//			return null;
//		}
            Map<String, Object> temp = new HashMap<String, Object>();
            ActionResult result = new ActionResult(false, "");
            String url = "";
            SheetMode sheetMode = SheetMode.Work;
            sheetMode = SheetMode.valueOf(Mode);
            if(this.ValidateAuthorization(BizObjectID, SchemaCode, sheetMode, SchemaCode)
                    == BoolMatchValue.False){
                result.setSuccess(false);
                result.setMessage("MvcController_Perission");
                temp.put("Message", result.getMessage());
                temp.put("Extend", result.getExtend());
                temp.put("ExceptionCode", result.getExceptionCode());
                temp.put("Success", result.getSuccess());
                return result;
            }
            if (!DotNetToJavaStringHelper.isNullOrEmpty(EditInstanceData))
            {
                url = GetWorkSheetUrl(SchemaCode, BizObjectID, sheetMode, IsMobile);
                url += "&EditInstanceData=true";
            }
            else
            {
                BizSheet sheet = this.getEngine().getBizSheetManager().GetBizSheetByCode(SheetCode);
                if (sheet == null)
                {
                    List<BizSheet> sheets = this.getEngine().getBizSheetManager()
                            .GetBizSheetBySchemaCode(SchemaCode);
                    if (sheets == null || sheets.size() == 0)
                    {
                        throw new RuntimeException("流程包{" + SchemaCode + "}表单不存在，请检查。");
                    }
                    sheet = sheets.get(0);
                }
                url = GetWorkSheetUrl(SchemaCode, BizObjectID, sheet, sheetMode, IsMobile);
                //update by ouyangsk 用户均有权限编辑流程表单，所以加个参数，这样MvcPage中Onload时，通过参数判断如果为应用中心流程表单，则不加以表单权限检验
                url += "&onlyData=true";
            }
            result.setMessage(url);
            result.setSuccess(true);

            temp.put("Message", result.getMessage());
            temp.put("Extend", result.getExtend());
            temp.put("ExceptionCode", result.getExceptionCode());
            temp.put("Success", result.getSuccess());
            return temp;
        }

        /**
         * @Title: ValidateAuthorization
         * @Description: 检查用户是否具有操作权限
         * @Param: @param BizObjectID
         * @Param: @param SchemaCode
         * @Param: @param SheetMode
         * @Param: @param WorkflowCode
         * @Param: @return
         * @Return: BoolMatchValue
         * @throws Exception
         * Add by linjh
         */
        public BoolMatchValue ValidateAuthorization(String BizObjectID, String SchemaCode,
                                                    SheetMode SheetMode, String WorkflowCode) throws Exception{
            //验证权限
            String instanceId = "";
            InstanceData instanceData = null;
            List<InstanceContext> context = this.getEngine().getInstanceManager()
                    .GetInstanceContextsByBizObject(SchemaCode, BizObjectID);
            if(context != null && context.size() > 0){
                instanceId = context.get(0).getInstanceId();
                instanceData = new InstanceData(
                        this.getEngine(), instanceId, this.getUserValidator().getUserID());
            }
            if(SheetMode == com.h3bpm.base.enums.SheetMode.Originate){
                //update by ouyangsk 根据需求，新增保存表单内容，不需检验数据模型权限
			/*if(getUserValidator().ValidateBizObjectAdd(
					SchemaCode, null, getUserValidator().getUserID())){
				return BoolMatchValue.True;
			}*/
                return BoolMatchValue.True;
            } else {
                if(getUserValidator().ValidateOrgAdmin(instanceData.getBizObject().getOwnerId())
                        || getUserValidator().ValidateBizObjectAdmin(
                        SchemaCode, null, instanceData.getBizObject().getOwnerId())){
                    return BoolMatchValue.True;
                }
            }
            return BoolMatchValue.False;
        }

        /**
         * 获取过滤条件数据
         *
         * @return 过滤条件数据
         * @throws Exception
         */
        @ResponseBody
        @RequestMapping(value="/GetVisibleFilterData",method={RequestMethod.GET,RequestMethod.POST})
        public final List<FilterDataViewModel> GetVisibleFilterData() throws Exception {
            List<FilterDataViewModel> list = new ArrayList<FilterDataViewModel>();
            if (getlstVisibleQueryItems() != null){
                //过滤类型为范围查询,强制变更为文本控件
                for (int i = 0; i < getlstVisibleQueryItems().size(); i++) {
                    BizQueryItem s = getlstVisibleQueryItems().get(i);

                    FilterDataViewModel tempVar = new FilterDataViewModel();
                    tempVar.setDefaultValue(s.getDefaultValue());
                    tempVar.setDisplayType(s.getFilterType() != FilterType.Scope.getValue()
                            ? s.getDisplayType() : ControlType.TextBox.getValue());
                    tempVar.setFilterType(s.getFilterType());
                    tempVar.setLogicType(GetPropertyLogicTypeByName(s.getPropertyCode()));
                    tempVar.setParentIndex(s.getParentIndex());
                    tempVar.setPropertyCode(s.getPropertyCode());
                    tempVar.setPropertyName(GetPropertyDisplayNameByName(s.getPropertyCode()));
                    tempVar.setPropertyType(s.getPropertyType().getValue());
                    //Update by linjh
                    tempVar.setSelectedValues(
                            GetFilterSelectedValues(s.getSelectedValues(),
                                    String.valueOf(s.getDisplayType()),
                                    //update by ouyangsk 根据propertyCode来获得LogicType类型
                                    //GetPropertyLogicTypeByName(s.getPropertyName())));
                                    GetPropertyLogicTypeByName(s.getPropertyCode())));
                    tempVar.setVisible(s.getVisible().getValue());

                    list.add(tempVar);//将对象添加到list
                }

            }
            return list;
        }

        /**
         * 获取下拉列表的值
         *
         * @param selectedValue
         * @param displayType
         * @return
         * @throws Exception
         * Update by linjh:增加参数及增加.net相应代码
         */
        private List<Item> GetFilterSelectedValues(String selectedValue, String displayType,
                                                   String logicType) throws Exception {
            List<Item> list = new ArrayList<Item>();
            List<EnumerableMetadata> enumDatas = null;
            if (!DotNetToJavaStringHelper.isNullOrEmpty(selectedValue)){
                enumDatas = this.getEngine().getMetadataRepository().GetByCategory(selectedValue);
            }

            if (ControlType.DropdownList.getValue() == Integer.parseInt(displayType)){
                list.add(new Item("全部",""));
            }
            if (enumDatas != null && enumDatas.size() > 0){
                for (int i = 0; i < enumDatas.size(); i++) {
                    EnumerableMetadata s = enumDatas.get(i);
                    Item temp = new Item();
                    temp.setValue(s.getCode());
                    temp.setText(s.getEnumValue());
                    list.add(temp);
                }
            } else {
                if (!DotNetToJavaStringHelper.isNullOrEmpty(selectedValue)){
                    TestServiceViewModel model = null;
                    MethodSchema method = null;

                    try {
                        ObjectMapper om = new ObjectMapper();
                        model = om.readValue(selectedValue, TestServiceViewModel.class);
                        if(model != null){
                            method = this.getEngine().getBizBus()
                                    .GetMethod(model.getServiceCode(), model.getRunMethod());
                        }
                    } catch (Exception e) {
                        LOGGER.error(">> " + e.toString());
                    }

                    if(model != null && method != null){
                        //查找方法的返回类型
                        //删除与组织结构对应的系统权限
                        BizStructure param = null;
                        if(method.getParamSchema() != null){
                            param = BizStructureUtility.Create(method.getParamSchema());
                        }
                        //调用方法
                        BizStructure ret = null;
                        try {
                            ret = this.getEngine().getBizBus().Invoke(
                                    new BizServiceInvokingContext(
                                            this.getUserValidator().getUserID(),
                                            model.getServiceCode(),
                                            method.getServiceVersion(),
                                            method.getMethodName(), param));
                        } catch (Exception e) {
                            LOGGER.error(">> " + e.toString());
                        }
                        //返回结果  UPDATE BY ZHANGJ
                        if(ret != null && ret.getSchema() != null){
                            Object[] objs = ret.getSchema().getItems();
                            for(Object ItemSchema : objs){
                                ItemSchema item = (ItemSchema) ItemSchema;
                                DataLogicType type = item.getLogicType();
                                //转换成相应的类型
                                Object obj = ret.getItem(item.getName());
                                if(type == DataLogicType.BizStructureArray){
                                    DataTable table = null;
                                    BizStructure[] bizStructures = (BizStructure[]) obj;
                                    if(bizStructures != null){
                                        for(BizStructure st : bizStructures){
                                            if(st != null){
                                                table = BizStructureUtility.ToTable(
                                                        st.getSchema(), bizStructures);
                                                break;
                                            }
                                        }
                                    }
                                    if(table != null && table.getRows().size() > 0){
                                        for(int i=0;i<table.getRows().size();i++){
                                            DataRow row = table.getRows().get(i);
                                            try {
                                                String Value = "";
                                                String Text = "";

                                                if (!DotNetToJavaStringHelper.isNullOrEmpty(
                                                        model.getText())
                                                        && !DotNetToJavaStringHelper.isNullOrEmpty(
                                                        model.getValue())
                                                        && row.getTable().getColumns().equals(
                                                        model.getText())
                                                        && row.getTable().getColumns().equals(
                                                        model.getValue())) {

                                                    Value = row.getString(model.getValue()) + "";
                                                    Text = row.getString(model.getText()) + "";

                                                } else if (row.getArrayList().length >= 2){

                                                    Value = row.getString(model.getValue());
                                                    Text = row.getString(model.getText()) + "";

                                                } else if (row.getArrayList().length == 1){

                                                    Value = row.getString(0);
                                                    Text = row.getString(0) + "";

                                                }

                                                Item temp = new Item();
                                                temp.setValue(Value);
                                                temp.setText(Text);
                                                list.add(temp);
                                            } catch (Exception e1) {
                                                LOGGER.error(">> " + e1.toString());
                                            }

                                        }
                                    }
                                }
                            }
                        }
                    } else {
                        boolean isBool = false;
                        if(logicType.equals(DataLogicType.Bool.toString())){
                            isBool = true;
                        }
                        String[] selectedValueArr = DotNetToJavaStringHelper
                                .trimEnd(selectedValue, ';').split(";");
                        for(String s : selectedValueArr){
                            Item temp = new Item();
                            temp.setValue(s);
                            temp.setText(isBool ? ("1".equals(s)?"True":"False"):s);
                            list.add(temp);
                        }

                    }
                }
            }
            return list;
        }

        /**
         * 根据名称获取业务对象的显示名称
         *
         * @param propertyName
         * @return
         * @throws Exception
         */
        public final String GetPropertyDisplayNameByName(String propertyName) throws Exception
        {
            PropertySchema propertySchema = GetPropertySchemaByName(propertyName);
            if (null == propertySchema)
            {
                return "";
            }
            else
            {
                return propertySchema.getDisplayName().toString();
            }
        }

        /**
         * 根据名称获取业务对象的逻辑类型
         *
         * @param propertyName
         * @return
         * @throws Exception
         */
        public final String GetPropertyLogicTypeByName(String propertyName) throws Exception
        {
            PropertySchema propertySchema = GetPropertySchemaByName(propertyName);
            if (null == propertySchema)
            {
                return "";
            }
            else
            {
                return propertySchema.getLogicType().toString();
            }
        }

        /**
         * 根据名称获取业务对象属性
         *
         * @param propertyName
         * @return
         * @throws Exception
         */
        private PropertySchema GetPropertySchemaByName(String propertyName) throws Exception
        {
            if (this.getSchema() != null)
            {
                return this.getSchema().GetProperty(propertyName);
            }
            return null;
        }


        /**
         * 获取显示格式
         *
         * @return 显示格式
         * @throws Exception
         */
        private Map<String, String> GetDisplayFormats() throws Exception
        {
            if (this.getQuery() != null && this.getQuery().getColumns() != null)
            {
                //ColumnName, DisplayFormat
                Map<String, String> dicDisplayFormats = new HashMap<String, String>();
                for (BizQueryColumn column : this.getQuery().getColumns())
                {
                    if (column.getVisible() == BoolMatchValue.True.getValue()
                            && !DotNetToJavaStringHelper.isNullOrEmpty(column.getDisplayFormat()))
                    {
                        if(column.getDisplayFormat().indexOf("null")==-1){
                            dicDisplayFormats.put(
                                    column.getPropertyName(),
                                    column.getDisplayFormat());
                        }
                    }
                }
                return dicDisplayFormats;

            }
            else
            {
                return null;
            }
        }


        /**
         * 获取组织显示的HTML
         *
         * @param Unit
         * @return
         * @throws InstantiationException
         * @throws IllegalAccessException
         */
        private String GetUnitDisplayHtml(Unit Unit)
                throws InstantiationException, IllegalAccessException
        {
            if (Unit != null)
            {
                String url = null;
                switch (Unit.getUnitType())
                {
                    case Group:
                        url = this.getPortalRoot().concat(
                                "/admin/TabMaster.html?url=/Portal/admin/Organization/"
                                        + "EditGroup.htmlMode=View&ID=")+ Unit.getObjectID();
                        break;
                    case OrganizationUnit:
                        url = this.getPortalRoot().concat(
                                "/admin/TabMaster.html?url=/Portal/admin/Organization/"
                                        + "EditOrgUnit.html?Mode=View&ID=") + Unit.getObjectID();
                        break;
                    case Post:
                        url = this.getPortalRoot().concat(
                                "/admin/TabMaster.html?url=/Portal/admin/Organization/"
                                        + "EditPost.html?Mode=View&ID=") + Unit.getObjectID();
                        break;
                    case User:
                        url = this.getPortalRoot().concat(
                                "/admin/TabMaster.html?url=/Portal/admin/Organization/"
                                        + "EditUser.html?Mode=View&ID=") + Unit.getObjectID();
                        break;
                    case Unspecified:
                    default:
                        break;
                }

                if (!DotNetToJavaStringHelper.isNullOrEmpty(url))
                {
                    return "" + Unit.getName();
                }
                else
                {
                    return "" + Unit.getName();
                }
            }
            return null;
        }


        /**
         * 获取查询条件
         *
         * @param filterStr
         * 			过滤条件
         * @return
         * @throws Exception
         * update by zhangj
         */
        protected final Filter GetFilter(String filterStr) throws Exception
        {
            // 构造查询条件
            Filter filter = new Filter();
            String paramName, paramValue;
            And and = new And();
            filter.setMatcher(and);
            // 获得需要的列
            List<String> columnList = new ArrayList<String>();
            PropertySchema[] properties = this.getSchema().getProperties();
            for (PropertySchema property : properties)
            {
                if (property.getTypeSearchable()
                        || property.getLogicType() == DataLogicType.MultiParticipant)
                {
                    columnList.add(property.getName());
                }
            }
            String[] columns = new String[columnList.size()];
            for (int i = 0; i < columns.length; i++) {
                columns[i] = columnList.get(i);
            }
            filter.setReturnItems(columns);

            if (getQuery().getColumns() == null)
            {
                throw new RuntimeException(
                        String.format("没有给主数据：%1$s的查询：%2$s添加可以显示的字段",
                                this.getSchemaCode(), this.getQueryCode()));
            }

            List<String> filterItems = new ArrayList<String>();
            if (getlstVisibleQueryItems() != null && getQuery().getQueryItems() != null)
            {
                String inputStr = getInputPropertyMappings().replace("|", "@");
                String[] paramValues = SplitUtil.Splits(inputStr, new String[] { "@" }, true);
                for (BizQueryItem queryItem : getQuery().getQueryItems())
                {
                    // 增加系统参数条件
                    //确认属性存在
                    if (queryItem.getFilterType() == FilterType.SystemParam.getValue()
                            && this.getSchema().GetProperty(queryItem.getPropertyName()) != null)
                    {
                        and.Add(new ItemMatcher(queryItem.getPropertyName(),
                                ComparisonOperatorType.Equal,
                                SheetUtility.GetSystemParamValue(
                                        this.getUserValidator(), queryItem.getDefaultValue())));
                    }
                    else if (queryItem.getVisible() == BoolMatchValue.False)
                    { // 隐藏的查询条件
                        for (String v : paramValues)
                        {
                            if (v.indexOf(",") > -1)
                            {
                                String key = v.substring(0, v.indexOf(","));
                                String value = v.substring(v.indexOf(",") + 1);
                                if (key.equals(queryItem.getPropertyName()))
                                {
                                    filterItems.add(queryItem.getPropertyName());
                                    and.Add(new ItemMatcher(queryItem.getPropertyName(),
                                            ComparisonOperatorType.Equal, value));
                                }
                            }
                        }
                    }
                }
            }

            ObjectMapper mapper = new ObjectMapper();
            JavaType javaType = mapper.getTypeFactory()
                    .constructParametricType(Map.class, String.class, Object.class);
            Map<String, Object> filterDic = new HashMap<String, Object>();
            if(!DotNetToJavaStringHelper.isNullOrEmpty(filterStr)){
                filterDic = mapper.readValue(filterStr, javaType);
            }

            //add by linjh@Future 2018.9.27 sql 注入
            for (String key : filterDic.keySet()){
                Object value = filterDic.get(key);
                if (value instanceof String) {
                    filterDic.put(key, StringEscapeUtils.escapeSql(String.valueOf(value)));
                }
            }
            List<FilterDataViewModel> filterList = GetVisibleFilterData();

            for (FilterDataViewModel filterItem : filterList)
            {
                paramName = paramValue = "";
                BizQueryItem query = GetQueryItemByName(getlstVisibleQueryItems(),
                        filterItem.getPropertyCode());
                paramName = filterItem.getPropertyCode();

                String start = null;
                String end = null;

                if (filterDic.containsKey(filterItem.getPropertyCode()))
                {
                    if(filterDic.get(filterItem.getPropertyCode())!=null
                            &&filterDic.get(filterItem.getPropertyCode()).toString().length() > 0){
                        /**
                         * 若查询添加编码包含 start和end  则说明是日期查询
                         * 若start与end为空  则默认最大值或最小值
                         * update by zhangj
                         */
                        if(filterDic.get(filterItem.getPropertyCode()).toString().indexOf("start") > 0
                                && filterDic.get(filterItem.getPropertyCode())
                                .toString().indexOf("end") > 0){
                            @SuppressWarnings("unchecked")
                            Map<String, Object> result = (Map<String, Object>) filterDic.get(filterItem.getPropertyCode());
                            start = (String) result.get("start");
                            if(DotNetToJavaStringHelper.isNullOrEmpty(start)){
                                result.put("start", DateTimeUtil.getDateToString(DateTimeUtil.minValue()));
                            }
                            end = (String) result.get("end");
                            if(DotNetToJavaStringHelper.isNullOrEmpty(end)){
                                result.put("end", DateTimeUtil.getDateToString(DateTimeUtil.maxValue()));
                            }
                        }
                        paramValue = DotNetToJavaStringHelper.trimEnd(
                                filterDic.get(filterItem.getPropertyCode()).toString(), ';');
                    }
                }
                //if(DotNetToJavaStringHelper.isNullOrEmpty(paramValue)){
                //paramValue = " ";
                //}
                if (filterItem.getFilterType() == 2) //范围查询
                {
                    ObjectMapper mapper2 = new ObjectMapper();
                    JavaType javaType2 = mapper2.getTypeFactory()
                            .constructParametricType(HashMap.class, String.class, String.class);
                    Map<String, String> child = mapper2.readValue(
                            JSONObject.fromObject(paramValue).toString(), javaType2);

                    String fromValue = child.containsKey("start") ? child.get("start") : "";
                    String toValue = child.containsKey("start") ? child.get("end") : "";
                    if (child.size() != 0)
                    {
                        //日期类型
                        if (DataLogicType.DateTime.toString().equals(filterItem.getLogicType()))
                        {
                            Date t = new Date();
                            try {
                                t = DateTimeUtil.getStringToDate(fromValue);
                            } catch (Exception e) {

                            }
                            if (DateTimeUtil.getYear(t) == 1 || DateTimeUtil.getYear(t) == 1753
                                    || DateTimeUtil.getYear(t) == 9999)
                            {
                                fromValue = "";
                            }
                            boolean tempVar = true;
                            try {
                                t = DateTimeUtil.getStringToDate(toValue);
                            } catch (Exception e) {
                                tempVar = false;
                            }

                            if (tempVar)
                            {
                                toValue = DateTimeUtil.getDateToString(t);
                            }
                            if (DateTimeUtil.getYear(t) == 1 || DateTimeUtil.getYear(t) == 1753
                                    || DateTimeUtil.getYear(t) == 9999)
                            {
                                toValue = "";
                            }
                        }
                        // 做范围查询
                        if (!"".equals(fromValue) && !"".equals(start))
                        {
                            and.Add(new ItemMatcher(paramName, ComparisonOperatorType.NotBelow,
                                    fromValue));
                        }
                        if (!"".equals(toValue) && !"".equals(end))
                        {
                            and.Add(new ItemMatcher(paramName, ComparisonOperatorType.NotAbove,
                                    toValue));
                        }
                    }

                }
                else
                {
                    // 模糊匹配，并且为空值 //update by zhangj
                    if (query == null)
                    {
                        continue;
                    }

                    String[] params = paramValue.split(";");
                    if (query != null && query.getFilterType() == FilterType.Contains.getValue())
                    {
                        // 模糊匹配   update by zhangj  针对复选框和下拉框   如果查询值是手动输入的默认值   则需要根据;号拆分各个查询值
                        if(params.length > 1){
                            for (int i = 0; i < params.length; i++) {
                                and.Add(new ItemMatcher(paramName, ComparisonOperatorType.In, params));
                            }
                        }else{
                            and.Add(new ItemMatcher(paramName, ComparisonOperatorType.Contain,
                                    paramValue));
                        }
                    }
                    else
                    { //完全匹配
                        if(!DotNetToJavaStringHelper.isNullOrEmpty(paramValue)){
                            if(params.length > 1){
                                for (int i = 0; i < params.length; i++) {
                                    and.Add(new ItemMatcher(paramName, ComparisonOperatorType.In,
                                            params));
                                }
                            }else{
                                and.Add(new ItemMatcher(paramName, ComparisonOperatorType.Equal,
                                        paramValue));
                            }
                        }
                    }
                }
            }
            if (getQuery().getQueryItems() != null)
            {
                //添加隐藏条件
                for (BizQueryItem item : getQuery().getQueryItems()) {
                    if (item.getVisible() == BoolMatchValue.False) {
                        if (item.getFilterType() != FilterType.SystemParam.getValue()
                                && !filterItems.contains(item.getPropertyName())) {
                            if (SheetUtility.GetSystemParamValue(this.getUserValidator(), item.getDefaultValue()) != null
                                    && !"".equals(
                                    SheetUtility.GetSystemParamValue(this.getUserValidator(), item.getDefaultValue()))) {
                                item.setDefaultValue(
                                        SheetUtility.GetSystemParamValue(this.getUserValidator(), item.getDefaultValue()));
                            }

                            and.Add(new ItemMatcher(
                                    item.getPropertyName(), item.getFilterType() == FilterType.Contains.getValue()
                                    ? ComparisonOperatorType.Contain : ComparisonOperatorType.Equal,
                                    item.getDefaultValue()));
                        }
                    }
                }
            }
            return filter;
        }

        /**
         * 根据名称获取查询条件
         *
         * @param queryItems
         * @param name
         * @return
         */
        private BizQueryItem GetQueryItemByName(List<BizQueryItem> queryItems, String name)
        {
            for (BizQueryItem queryItem : queryItems)
            {
                if (name.equals(queryItem.getPropertyCode()))
                {
                    return queryItem;
                }
            }
            return null;
        }

        /**
         * 获取查询动作
         *
         * @return 查询动作
         * @throws Exception
         */
        private List<BizQueryAction> GetActions() throws Exception
        {

            if (this.getActionVisible())
            {
                List<BizQueryAction> BizQueryActions = this.getQuery().getBizActions();
                if (BizQueryActions != null && BizQueryActions.size() > 0)
                {
                    for (BizQueryAction action : BizQueryActions)
                    {
                        if (DotNetToJavaStringHelper.isNullOrEmpty(action.getIcon()))
                        {
                            if (action.getActionCode().equals("AddNew"))
                            {
                                action.setIcon("fa fa-plus");
                            }
                            if (action.getActionCode().equals("Edit"))
                            {
                                action.setIcon("fa fa-edit");
                            }
                            if (action.getActionCode().equals("Delete"))
                            {
                                action.setIcon("fa fa-minus");
                            }
                        }
                        if (action.getActionType() == ActionType.OpenUrl.getValue()
                                && !DotNetToJavaStringHelper.isNullOrEmpty(action.getUrl())
                                && !action.getUrl().toLowerCase().startsWith("http:")
                                && !action.getUrl().toLowerCase().startsWith("https:"))
                        {
                            if (action.getUrl().toLowerCase().startsWith("www."))
                            {
                                action.setUrl("http://" + action.getUrl());
                            }
                            else
                            {
                                action.setUrl(GetUriPath(action.getUrl()));
                            }
                        }

                    }
                }
                return BizQueryActions;
            }
            else
            {
                return null;
            }
        }

        /**
         获取解析后的URI路径，对于存在 Portal

         @param url
         @return
         */
        public final String GetUriPath(String url)
        {
            if (this.getPortalRoot().equals(""))
            {
                return url;
            }
            if (DotNetToJavaStringHelper.isNullOrEmpty(url))
            {
                return null;
            }
            return this.getPortalRoot().concat(url).replace("\\", "/");
        }

        /**
         * 获取表头
         *
         * @throws Exception
         */
        private void CreateColumns() throws Exception
        {
            Map<String, String> dicCloumns = null;
            if (this.getQuery().getColumns() != null)
            {
                for (BizQueryColumn column : this.getQuery().getColumns())
                {
                    if (column.getVisible() == BoolMatchValue.True.getValue())
                    {
                        PropertySchema p = this.getSchema().GetProperty(column.getPropertyName());
                        if (p == null)
                        {
                            continue;
                        }
                        dicCloumns = new java.util.HashMap<String, String>();
                        dicCloumns.put("display", p == null ? p.getName() : p.getDisplayName());
                        dicCloumns.put("name", p.getName());
                        if (column.getWidth() > 0)
                        {
                            dicCloumns.put("width", column.getWidth()+"");
                        }
                        else if (column.getWidth() < 0)
                        {
                            dicCloumns.put("hide", "true");
                        }
                        GirdColumns.add(dicCloumns);
                    }
                }
            }
        }

        /**
         * @Title: GetGridDataForPortal
         * @Description: 获取列表数据
         * @Param: @param schemaCode 数据模型编码
         * @Param: @param queryCode 查询编码
         * @Param: @param filterStr 过滤条件
         * @Param: @param pageInfo 分页信息
         * @Param: @return 列表数据
         * @Return: ActionResult
         * @throws Exception
         * Add by linjh
         */
        @ResponseBody
        @RequestMapping(value="/GetGridDataForPortal",method={RequestMethod.POST,RequestMethod.GET})
        public Object GetGridDataForPortal(String schemaCode, String queryCode, String filterStr,
                                           PagerInfo pageInfo) throws Exception{

            //add by hxc
            filterStr=StringEscapeUtils.escapeSql(filterStr);
            schemaCode=StringEscapeUtils.escapeSql(schemaCode);
            queryCode=StringEscapeUtils.escapeSql(queryCode);


            if (StringUtils.isEmpty(queryCode) || Objects.equals(queryCode, "null")) {
                return ActionResult.fail("RunBizQuery.QueryCodeEmpty");
            }

            this.setSchemaCode(URLDecoder.decode(schemaCode,"utf-8"));
            this.setQueryCode(URLDecoder.decode(queryCode,"utf-8"));
            int totalCount  = 0;
            if(DotNetToJavaStringHelper.isNullOrEmpty(filterStr)){
                filterStr = "{}";
            }
            //add by linjh@Future 2018.9.27 sql 注入 TODO 门户页面报错了
//		if (!"{}".equals(filterStr)){
//			JSONObject filterJsonObject = JSONObject.fromObject(filterStr);
//			Map<String, String> dicParams = (Map<String, String>)JSONObject.toBean(filterJsonObject, Map.class);
//			for (String key : dicParams.keySet()){
//				String temp = dicParams.get(key);
//				if (temp == null || "".equals(temp)){
//					continue;
//				}
//				temp = temp.replaceAll("'","").replaceAll(";","").replaceAll("%27","").replaceAll("%3B","").replaceAll("--","");
//				dicParams.put(key, temp);
//			}
//			filterStr = JSONObject.fromObject(dicParams).toString();
//		}
            RefObject<Integer> tempRef_totalCount = new RefObject<Integer>(totalCount);
            List<Object> dataList = GetGridDataListForPortal(filterStr, pageInfo, tempRef_totalCount);
            totalCount = tempRef_totalCount.argvalue;

            GridViewModel<Object> result = new GridViewModel<Object>(
                    totalCount, dataList, pageInfo.getsEcho());
            return result;
        }


        /**
         * 门户应用中心调用此方法
         *
         * @Title: GetGridDataList
         * @Description: 获取查询出的数据列以及总大小
         * @Param: @param filterStr 过滤参数
         * @Param: @param pageInfo 分页信息
         * @Param: @param totalCount 返回的总数
         * @Param: @return 表格数据
         * @Return: List<Object>
         * @throws Exception
         * Add by linjh
         */
        private List<Object> GetGridDataListForPortal(String filterStr, PagerInfo pageInfo,
                                                      RefObject<Integer> totalCount) throws Exception{
            Filter filter = GetFilter(filterStr);
            totalCount.argvalue = 0;
            int pageSize = pageInfo.getPageSize();
            int currentPageIndex = pageInfo.getPageIndex();

            //点击排序支持
            String SortName = this.request.getParameter("sortname");
            String SortOrder = this.request.getParameter("sortorder");
            SortDirection sortDirection = SortDirection.Ascending;
            if (!DotNetToJavaStringHelper.isNullOrEmpty(SortName)){
                if (!DotNetToJavaStringHelper.isNullOrEmpty(SortOrder)
                        && "desc".equals(SortOrder.toLowerCase())){
                    sortDirection = SortDirection.Descending;
                }
            } else {//如果没有指定排序,默认取第一列
              /*  for (int i = 0; i < getQuery().getColumns().size(); i++){
                    if (getQuery().getColumns().get(i).getVisible() == BoolMatchValue.True.getValue()){
                        filter.AddSortBy(new SortBy(getQuery().getColumns().get(i).getPropertyName(),
                                SortDirection.Ascending));
                        break;
                    }
                }*/
                filter.AddSortBy("ModifiedTime", SortDirection.Descending);
            }
            filter.AddSortBy(new SortBy(SortName, sortDirection));

            if (filter.getSortByCollection() == null || filter.getSortByCollection().length == 0){
                for (BizQueryColumn column : getQuery().getColumns()){
                    if (column.getVisible() == BoolMatchValue.True.getValue()){
                        filter.AddSortBy(new SortBy(column.getPropertyName(), SortDirection.Ascending));
                        break;
                    }
                }
            }

            if (pageSize > 0){
                filter.setFromRowNum((currentPageIndex - 1) * pageSize < 1
                        ? 1 : (currentPageIndex - 1) * pageSize + 1);
                filter.setToRowNum(filter.getFromRowNum() + pageSize - 1);
            }
            filter.setRequireCount(true);

            // 调用查询
            BizObject[] objs = this.getSchema().GetList(
                    this.getEngine().getOrganization(),
                    this.getEngine().getMetadataRepository(),
                    this.getEngine().getBizObjectManager(),
                    this.getUserValidator().getUserID(),
                    getListMethod(),
                    filter,
                    totalCount);
            List<Object> dataList = new ArrayList<Object>();
            if (objs != null){
                //update by zhangj
                for (int i = 0; i < objs.length; i++) {
                    BizObject biz = objs[i];
                    for (int j = 0; j < getQuery().getColumns().size(); j++) {
                        Object o = biz.getItem(getQuery().getColumns().get(j).getPropertyName());
                        //审批意见
                        //子表
                        if(o != null && o instanceof BizObject[]){
                            biz.setItem(getQuery().getColumns().get(j).getPropertyName(), "");
                            continue;
                        }
                        if(o != null && o instanceof Object[]){
                            Object[] obj = (Object[]) o;
                            if(obj != null && obj[0] instanceof String){
                                //参与者类型在后面代码处理 UPDATE BY ZHANGJ
                                continue;
                            }
                            ItemSchema is = (ItemSchema) obj[0];
                            if(DataLogicType.Comment == is.getLogicType()){
                                biz.setItem(getQuery().getColumns().get(j).getPropertyName(), "");
                            }
                            if(DataLogicType.Attachment == is.getLogicType()){
                                biz.setItem(getQuery().getColumns().get(j).getPropertyName(), "");
                            }
                        }
                        if(o instanceof ItemSchema){
                            ItemSchema is = (ItemSchema) o;
                            if(is.getLogicType() == DataLogicType.Attachment){
                                biz.setItem(getQuery().getColumns().get(j).getPropertyName(), "");
                            }
                        }
                    }
                }

                //业务对象数组类型的属性名称
                List<String> VisiblePropertyNames = new ArrayList<String>();
                if (this.getSchema().getProperties() != null){
                    for(PropertySchema p : this.getSchema().getProperties()){
                        VisiblePropertyNames.add(p.getName());
                    }
                }

                List<String> UnitIDList = new ArrayList<String>();
                // 业务对象
                for(BizObject obj : objs){
                    Map<String, Object> dicValueTable = new HashMap<String, Object>();
                    if (obj.getValueTable() != null){
                        for(String pName : VisiblePropertyNames){
                            if (obj.getValueTable().containsKey(pName)){
                                //单人参与者
                                if (this.getSchema().GetProperty(pName).getLogicType()
                                        == DataLogicType.SingleParticipant
                                        || pName.equals(BizObjectSchema.PropertyName_CreatedBy)
                                        || pName.equals(BizObjectSchema.PropertyName_CreatedByParentId)){

                                    UnitIDList.add(obj.getValueTable().get(pName) + "");

                                } else if (this.getSchema().GetProperty(pName).getLogicType()
                                        == DataLogicType.MultiParticipant) {
                                    //多人参与者
                                    String[] participants = (String[]) obj.getValueTable().get(pName);
							/*	String tmp=(String)obj.getValueTable().get(pName);
								String[] participants=null;
								if(!DotNetToJavaStringHelper.isNullOrEmpty(tmp)){
									tmp=tmp.replaceAll("\\[","");
									tmp=tmp.replaceAll("\\]","");
									participants=tmp.split(",");
								}*/
                                    if (participants != null && participants.length > 0){
                                        for(String participant : participants){
                                            UnitIDList.add(participant);
                                        }
                                    }

                                }
                            }
                        }

                        List<Unit> Units = this.getEngine().getOrganization().GetUnits(UnitIDList);
                        Map<String, String> UnitDictionary = new HashMap<String, String>();
                        for (Unit u : Units) {
                            if (!UnitDictionary.containsKey(u.getObjectID())) {
                                UnitDictionary.put(u.getObjectID(), u.getName());
                            }
                        }
				/*	Unit[] Units = temp.toArray(new Unit[temp.size()]);
					// <UnitID,Unit>
					Map<String, Unit> UnitDictionary = new HashMap<String, Unit>();
					if (Units != null && Units.length > 0){
						for(Unit u : Units){
							if (!UnitDictionary.containsKey(u.getObjectID())){
								UnitDictionary.put(u.getObjectID(), u);
							}
						}
					}*/

                        for(String pName : VisiblePropertyNames){
                            if (obj.getValueTable().containsKey(pName)){
                                //单人参与者
                                if (this.getSchema().GetProperty(pName).getLogicType()
                                        == DataLogicType.SingleParticipant
                                        || pName.equals(BizObjectSchema.PropertyName_CreatedBy)
                                        || pName.equals(BizObjectSchema.PropertyName_CreatedByParentId)){

								/*if (UnitDictionary.containsKey(obj.getValueTable().get(pName) + "")){
									dicValueTable.put(pName, GetUnitDisplayHtml(UnitDictionary
											.get(obj.getValueTable().get(pName) + "")));
								} else {
									dicValueTable.put(pName, obj.getValueTable().get(pName) + "");
								}*/
                                    dicValueTable.put(pName, UnitDictionary.get(obj.getValueTable().get(pName) + "") == null ? obj.getValueTable().get(pName) : UnitDictionary.get(obj.getValueTable().get(pName) + ""));

                                } else if (this.getSchema().GetProperty(pName).getLogicType()
                                        == DataLogicType.MultiParticipant) {
                                    //多人参与者
                                    String[] participants = (String[]) obj.getValueTable().get(pName);
							/*	String tmp=(String)obj.getValueTable().get(pName);
								String[] participants=null;
								if(!DotNetToJavaStringHelper.isNullOrEmpty(tmp)){
									tmp=tmp.replaceAll("\\[","");
									tmp=tmp.replaceAll("\\]","");
									participants=tmp.split(",");
								}*/
                                    if (participants != null && participants.length > 0){
                                        String multiParticipantString = "";
                                        for(String participant : participants) {
                                            if (UnitDictionary.containsKey(participant)) {
                                                multiParticipantString += UnitDictionary.get(participant) + ";";
                                            } else {
                                                multiParticipantString += participant + ";";
                                            }
                                        }
                                        dicValueTable.put(pName, multiParticipantString);

                                    } else {
                                        dicValueTable.put(pName, obj.getValueTable().get(pName));
                                    }
                                } else if (this.getSchema().GetProperty(pName).getLogicType()
                                        == DataLogicType.TimeSpan) {
                                    //时间段
                                    if (null != obj.getValueTable().get(pName)) {
                                        String timeSpanStr = "";
                                        TimeSpan timeSpan = (TimeSpan)obj.getValueTable().get(pName);
                                        timeSpanStr = timeSpan.toString();
                                        dicValueTable.put(pName, timeSpanStr);
                                    }
                                } else if (this.getSchema().GetProperty(pName).getLogicType()
                                        == DataLogicType.DateTime) {
                                    //时间
                                    if (null != obj.getValueTable().get(pName)) {
                                        //update by zhangj
                                        Date date = DateTimeUtil.getStringToDate(
                                                obj.getValueTable().get(pName).toString());
                                        Long dateNo = date.getTime();
                                        dicValueTable.put(pName, "/Date(" + dateNo + ")/");
                                    }
                                } else if (this.getSchema().GetProperty(pName).getLogicType()
                                        == DataLogicType.Comment) {
                                    //update by ouyangsk 审批意见不显示
                                    dicValueTable.put(pName, "");
                                } else {
                                    dicValueTable.put(pName, obj.getValueTable().get(pName));
                                }
                            }
                        }
                    }
                    dataList.add(dicValueTable);
                }
            }
            return dataList;
        }

        /**
         * @Title: GetBizQueryViewData
         * @Description: 查询列表数据查询
         * @Param: @param schemaCode
         * @Param: @param queryCode
         * @Param: @param filterStr
         * @Param: @param pageInfo
         * @Param: @return
         * @Return: Object
         * @throws Exception
         * Add by linjh
         */
        @ResponseBody
        @RequestMapping(value="/GetBizQueryViewData",method=RequestMethod.POST)
        public Object GetBizQueryViewData(String schemaCode, String queryCode, String filterStr,
                                          PagerInfo pageInfo) throws Exception{
            if (StringUtils.isEmpty(queryCode) || Objects.equals(queryCode, "null")) {
                return ActionResult.fail("RunBizQuery.QueryCodeEmpty");
            }
            ActionResult actionResult = new ActionResult(false);
            Map<String, Object> param = new HashMap<String, Object>();
            Map<String, Object> actionFilter = new HashMap<String, Object>();
            actionFilter.put("ContentEncoding", null);
            actionFilter.put("ContentType", null);
            actionFilter.put("Data", GetRunBizQueryData(schemaCode, queryCode));
            actionFilter.put("JsonRequestBehavior", 0);
            actionFilter.put("MaxJsonLength", null);
            actionFilter.put("RecursionLimit", null);
            param.put("ActionFilter", actionFilter);
            param.put("DisplayFormats", GetDisplayFormats());
            actionResult.setSuccess(true);
            actionResult.setExtend(param);
            Map<String, Object> result = new HashMap<String, Object>();
            result.put("Success", actionResult.getSuccess());
            result.put("Extend", actionResult.getExtend());
            result.put("ExceptionCode", actionResult.getExceptionCode().getValue());
            result.put("Message", actionResult.getMessage());
            //update by ouyangsk 判断当前用户是否具有相对应的数据模型管理权限
            String currentUserId = this.getUserValidator().getUserID();
            List<String> userList = new ArrayList<String>();
            userList.add(currentUserId);
            List<BizObjectAcl>  boaList = this.getEngine().getBizObjectManager().GetBizObjectAcls(schemaCode, "");
            List<UnitType> unitTypeList = new ArrayList<UnitType>();
            unitTypeList.add(UnitType.User);
            unitTypeList.add(UnitType.OrganizationUnit);
            unitTypeList.add(UnitType.Group);
            boolean createBizObject = false;
            //boolean viewData = false;
            boolean administrator = false;
            if (this.getUserValidator().getUser().getIsAdministrator()) {
                createBizObject = true;
                administrator = true;
            } else {
                List<UnitType> unitTypes = new ArrayList<UnitType>();
                unitTypes.add(UnitType.OrganizationUnit);
                unitTypes.add(UnitType.User);
                unitTypes.add(UnitType.Group);

                for (BizObjectAcl  boa : boaList) {
                    String userId = boa.getUserID();
                    if (userId.equals(currentUserId)) {
                        if (!createBizObject && boa.getCreateBizObject()) {
                            createBizObject = true;
                        }
                        if (!administrator && boa.getAdministrator()) {
                            administrator = true;
                        }
                    } else {
                        //查找组织下面的用户
                        List<Unit> units = this.getEngine().getOrganization().GetChildUnits(userId, unitTypes, true, State.Active);
                        for (Unit tempUnit : units) {
                            if (!currentUserId.equals(tempUnit.getObjectID())) {
                                continue;
                            }
                            if (!createBizObject && boa.getCreateBizObject()) {
                                createBizObject = true;
                            }
                            if (!administrator && boa.getAdministrator()) {
                                administrator = true;
                            }
                        }
                    }
                }
            }

            result.put("btnAddFlag", createBizObject);
            result.put("btnAdministratorFlag", administrator);
            return result;
        }




}
